//
//  BShopNoIncomeVC.m
//  DistributorAB
//
//  Created by LZY on 2019/9/30.
//  Copyright © 2019 主事丫环. All rights reserved.
//


#import "BShopNoIncomeVC.h"

#import "BwuSetwViewController.h"
#import "CSPersonModel.h"
#import "BBuildingShopViewController.h"
#import "BgoodsAdminViewController.h"
#import "BorderAdminViewController.h"
#import "BadminMoneyViewController.h"
#import "BadminShopViewController.h"
#import "CSaddPerCardViewController.h"
#import "CSIdAuthViewController.h"
#import "XSQBanner.h"
#import "BannerImgsModel.h"

#import "BShopNoIncomeMenuView.h"//底部菜单控件
#import "BBussinessLicenseVC.h"//上传营业执照
#import "BBussinessLicenseAuditVC.h"//营业执照审核
#import "BBussinessLicenseAuditFailVC.h"//营业执照审核失败
@interface BShopNoIncomeVC () <BShopNoIncomeMenuViewDelegate>
@property (nonatomic, strong) UILabel *lblTodayMoney;//今日营业额
@property (nonatomic, strong) UILabel *lblSend;//待发货
@property (nonatomic, strong) UILabel *lblPay;//待付款
@property (nonatomic,strong) CSPersonModel *personmodel;//用户信息
@end

@implementation BShopNoIncomeVC

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    //状态栏字体白色
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    [self request];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    //状态栏字体黑色
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupNavViewAction];
    [self setupViewAction];
    
    [self requestUserInfoIsInit:YES];
}

#pragma mark - 界面布局方法
- (void)setupNavViewAction{
    UIView *viewNav = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, kNaviHeight)];
    [self.view addSubview:viewNav];
    
    UIImageView *ivBg = [[UIImageView alloc] initWithFrame:viewNav.bounds];
    ivBg.image = imgname(@"base_nav_bg");
    [viewNav addSubview:ivBg];
    
    UILabel *lblNav = [[UILabel alloc] initWithFrame:CGRectMake(0, kNaviHeight - 44, kScreen_Width, 44)];
    lblNav.text = @"我的店铺";
    lblNav.font = [UIFont systemFontOfSize:18];
    lblNav.textColor = kColorWithHex(0xffffff);
    lblNav.textAlignment = NSTextAlignmentCenter;
    [viewNav addSubview:lblNav];
    
    UIButton *btnSet = [UIButton buttonWithType:UIButtonTypeCustom];
    btnSet.frame = CGRectMake(kScreen_Width - 41, kNaviHeight - 37, 30, 30);
    [btnSet setImage:imgname(@"shop_set_icon") forState:UIControlStateNormal];
    [btnSet addTarget:self action:@selector(btnSetClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [viewNav addSubview:btnSet];
}
- (void)setupViewAction{
    
    UIView *viewTop = [[UIView alloc] initWithFrame:CGRectMake(0, kNaviHeight, kScreen_Width, 226)];
    viewTop.backgroundColor = kColorWithHex(0xffffff);
    [self.view addSubview:viewTop];
    
    UIView *viewLine = [[UIView alloc] initWithFrame:CGRectMake(0, 211, kScreen_Width, 15)];
    viewLine.backgroundColor = kColorWithHex(0xf8f8f8);
    [viewTop addSubview:viewLine];
    
    UILabel *lblTodayNotice = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, kScreen_Width, 22)];
    lblTodayNotice.text = @"今日营业额(元)";
    lblTodayNotice.font = [UIFont systemFontOfSize:16];
    lblTodayNotice.textColor = kColorWithHex(0x70be68);
    lblTodayNotice.textAlignment = NSTextAlignmentCenter;
    [viewTop addSubview:lblTodayNotice];
    
    _lblTodayMoney = [[UILabel alloc] initWithFrame:CGRectMake(0, 67, kScreen_Width, 30)];
    _lblTodayMoney.text = @"0.00";
    _lblTodayMoney.font = [UIFont boldSystemFontOfSize:22];
    _lblTodayMoney.textColor = kColorWithHex(0x70be68);
    _lblTodayMoney.textAlignment = NSTextAlignmentCenter;
    [viewTop addSubview:_lblTodayMoney];
    
    UILabel *lblLine = [[UILabel alloc] initWithFrame:CGRectMake((kScreen_Width - 1) / 2.0, 157, 1, 26)];
    lblLine.backgroundColor = kColorWithHex(0xe7e9f8);
    [viewTop addSubview:lblLine];
    
    UILabel *lblSendNotice = [[UILabel alloc] initWithFrame:CGRectMake(0, 152, kScreen_Width / 2.0, 20)];
    lblSendNotice.text = @"待发货";
    lblSendNotice.font = [UIFont systemFontOfSize:14];
    lblSendNotice.textColor = kColorWithHex(0x7f7f7f);
    lblSendNotice.textAlignment = NSTextAlignmentCenter;
    [viewTop addSubview:lblSendNotice];
    
    UILabel *lblPayNotice = [[UILabel alloc] initWithFrame:CGRectMake(kScreen_Width / 2.0, 152, kScreen_Width / 2.0, 20)];
    lblPayNotice.text = @"待付款";
    lblPayNotice.font = [UIFont systemFontOfSize:14];
    lblPayNotice.textColor = kColorWithHex(0x7f7f7f);
    lblPayNotice.textAlignment = NSTextAlignmentCenter;
    [viewTop addSubview:lblPayNotice];
    
    _lblSend = [[UILabel alloc] initWithFrame:CGRectMake(0, 171, kScreen_Width / 2.0, 24)];
    _lblSend.text = @"0";
    _lblSend.font = [UIFont systemFontOfSize:17];
    _lblSend.textColor = kColorWithHex(0x7f7f7f);
    _lblSend.textAlignment = NSTextAlignmentCenter;
    [viewTop addSubview:_lblSend];
    
    _lblPay = [[UILabel alloc] initWithFrame:CGRectMake(kScreen_Width / 2.0, 171, kScreen_Width /2.0, 24)];
    _lblPay.text = @"0.00";
    _lblPay.font = [UIFont systemFontOfSize:17];
    _lblPay.textColor = kColorWithHex(0x7f7f7f);
    _lblPay.textAlignment = NSTextAlignmentCenter;
    [viewTop addSubview:_lblPay];
    
    UIButton *btnLeft = [UIButton buttonWithType:UIButtonTypeCustom];
    btnLeft.frame = CGRectMake(10, 152, (kScreen_Width - 40) / 2.0, 44);
    btnLeft.tag = 200;
    [btnLeft addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [viewTop addSubview:btnLeft];
    UIButton *btnRight = [UIButton buttonWithType:UIButtonTypeCustom];
    btnRight.frame = CGRectMake(CGRectGetMaxX(btnLeft.frame) + 20, 152, btnLeft.width, 44);
    btnRight.tag = 201;
    [btnRight addTarget:self action:@selector(btnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [viewTop addSubview:btnRight];
    
    UIView *viewLineV = [[UIView alloc] initWithFrame:CGRectMake((kScreen_Width - 1) / 2.0, CGRectGetMaxY(viewTop.frame) + 21, 1, 239)];
    viewLineV.backgroundColor = kColorWithHex(0xe5e5e5);
    [self.view addSubview:viewLineV];
    UIView *viewLineH = [[UIView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(viewTop.frame) + 141, kScreen_Width - 40, 1)];
    viewLineH.backgroundColor = kColorWithHex(0xe5e5e5);
    [self.view addSubview:viewLineH];
    
    BShopNoIncomeMenuView *viewGoods = [[BShopNoIncomeMenuView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(viewTop.frame), kScreen_Width / 2.0, 141)];
    viewGoods.delegate = self;
    viewGoods.viewType = BShopNoIncomeMenuViewTypeGoods;
    [self.view addSubview:viewGoods];
    
    BShopNoIncomeMenuView *viewOrder = [[BShopNoIncomeMenuView alloc] initWithFrame:CGRectMake(kScreen_Width / 2.0, CGRectGetMaxY(viewTop.frame), kScreen_Width / 2.0, 141)];
    viewOrder.delegate = self;
    viewOrder.viewType = BShopNoIncomeMenuViewTypeOrder;
    [self.view addSubview:viewOrder];
    
    BShopNoIncomeMenuView *viewMoney = [[BShopNoIncomeMenuView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(viewGoods.frame), kScreen_Width / 2.0, 141)];
    viewMoney.delegate = self;
    viewMoney.viewType = BShopNoIncomeMenuViewTypeMoney;
    [self.view addSubview:viewMoney];
    
    BShopNoIncomeMenuView *viewShop = [[BShopNoIncomeMenuView alloc] initWithFrame:CGRectMake(kScreen_Width / 2.0, CGRectGetMaxY(viewGoods.frame), kScreen_Width / 2.0, 141)];
    viewShop.delegate = self;
    viewShop.viewType = BShopNoIncomeMenuViewTypeShop;
    [self.view addSubview:viewShop];
    
    
}
#pragma mark - 请求营业数据
-(void)request{
    kWeakSelf;
    [NetWorkTool POST:BshopshopIndex param:nil success:^(id dic) {
        NSDictionary *dicData = [dic objectForKey:@"data"];
        NSString *todayMoney = [NSString stringWithFormat:@"%@",[dicData objectForKey:@"todayEar"]];
        if (strIsEmpty(todayMoney)) {
            todayMoney = @"0.00";
        }
        weakSelf.lblTodayMoney.text = todayMoney;
        weakSelf.lblSend.text = [NSString stringWithFormat:@"%@",[dicData objectForKey:@"notsend"]];
        weakSelf.lblPay.text = [NSString stringWithFormat:@"%.2f",[[dicData objectForKey:@"notpay"]floatValue]];
    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
    } fail:^(NSError *error) {
        
    } needUser:YES];
}

#pragma mark - 产品管理点击请求数据
- (void)requestUserInfoIsInit:(BOOL)isInit{
    if (!_personmodel) {
        _personmodel = [[CSPersonModel alloc]init];
    }
    kWeakSelf;
    [NetWorkTool POST:CcentenInfo param:nil success:^(id dic) {
        weakSelf.personmodel = [CSPersonModel mj_objectWithKeyValues:[dic objectForKey:@"data"]];
        if (isInit) {
            //初始化时刻
            if(strIsEmpty(weakSelf.personmodel.shopid)){
                //去认证店铺
                [self.navigationController pushViewController:[BBuildingShopViewController new] animated:YES];
                return ;
            }
            if (strIsEmpty(weakSelf.personmodel.id_card)) {
                //没绑定身份证 去绑定
                CSIdAuthViewController *bild = [[CSIdAuthViewController alloc]init];
                bild.iscenter = @"center";
                [weakSelf.navigationController pushViewController:bild animated:YES];
                return ;
            }
        }else{
            //非初始化时刻
            [weakSelf handleUserInfoModel];
        }
    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
    } fail:^(NSError *error) {
        
    } needUser:YES];
    
}
- (void)handleUserInfoModel{
    
    if ([self.personmodel.licenseState integerValue] == -1) {
        //拒绝
        BBussinessLicenseAuditFailVC *vc = [BBussinessLicenseAuditFailVC new];
        vc.auditFailReason = self.personmodel.licenseRefuseReason;
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([self.personmodel.licenseState integerValue] == 0){
        //未上传
        [self.navigationController pushViewController:[BBussinessLicenseVC new] animated:YES];
    }else if ([self.personmodel.licenseState integerValue] == 1){
        //审核中
        BBussinessLicenseAuditVC *vc = [BBussinessLicenseAuditVC new];
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([self.personmodel.licenseState integerValue] == 2){
        //审核通过
        [self.navigationController pushViewController:[BgoodsAdminViewController new] animated:YES];
    }
}
#pragma mark - 交互处理事件
- (void)btnSetClickAction:(UIButton *)sender{
    BwuSetwViewController *ser = [[BwuSetwViewController alloc]init];
    ser.model = _personmodel;
    [self.navigationController pushViewController:ser animated:YES];
}
- (void)btnClickAction:(UIButton *)sender{
    NSInteger tag = sender.tag;
    if (tag == 200) {
        //待发货
        BorderAdminViewController *order = [[BorderAdminViewController alloc]init];
        order.seleInd = 2 ;
        [self.navigationController pushViewController:order animated:YES];
    }else if (tag == 201){
        //待付款
        BorderAdminViewController *order = [[BorderAdminViewController alloc]init];
        order.seleInd = 1;
        [self.navigationController pushViewController:order animated:YES];
    }
}

#pragma mark - BShopNoIncomeMenuViewDelegate
- (void)shopNoIncomeMenuViewClick:(BShopNoIncomeMenuViewType)type{
    if (type == BShopNoIncomeMenuViewTypeGoods) {
        //产品管理
        if ([self.personmodel.licenseState integerValue] == 2){
            //审核通过
            [self.navigationController pushViewController:[BgoodsAdminViewController new] animated:YES];
        }else{
            [self requestUserInfoIsInit:NO];
        }
    }else if (type == BShopNoIncomeMenuViewTypeOrder){
        //订单管理
        [self.navigationController pushViewController:[BorderAdminViewController new] animated:YES];
    }else if (type == BShopNoIncomeMenuViewTypeMoney){
        //资金管理
        [self.navigationController pushViewController:[BadminMoneyViewController new] animated:YES];
    }else if (type == BShopNoIncomeMenuViewTypeShop){
        //店铺信息
        [self.navigationController pushViewController:[BadminShopViewController new] animated:YES];
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
